package com.sansui.blog.service.impl;

import com.sansui.blog.dao.SysMenuDao;
import com.sansui.blog.pojo.sys.HomeInfo;
import com.sansui.blog.pojo.sys.Init;
import com.sansui.blog.pojo.sys.LogoInfo;
import com.sansui.blog.pojo.sys.SysMenu;
import com.sansui.blog.service.SysMenuService;
import com.sansui.blog.utils.TreeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @name: SysMenuServiceImpl
 * @author: Sansui
 * @Software: IDEA
 * @Blog: https://www.cnblogs.com/sansui6/
 * @date: 2022-03-20 17:57
 **/

@Service
public class SysMenuServiceImpl implements SysMenuService {

    @Autowired
    private SysMenuDao sysMenuDao;


    /**
     * 获取后台菜单配置
     * @return
     */
    @Override
    public Map<String, Object> menuInit() {
        Map<String, Object> map = new HashMap<>(16);
        Map<String,Object> home = new HashMap<>(16);
        Map<String,Object> logo = new HashMap<>(16);
        List<Init> menuList = sysMenuDao.findAllByStatus(true);

        HomeInfo homeInfo = sysMenuDao.getHomeInfo();
        LogoInfo logoInfo = sysMenuDao.getLogoInfo();

        home.put("title",homeInfo.getTitle());
        home.put("href",homeInfo.getHref());

        logo.put("title",logoInfo.getTitle());
        logo.put("image",logoInfo.getImage());
        logo.put("href",logoInfo.getHref());

        map.put("homeInfo", home);
        map.put("logoInfo", logo);

        map.put("menuInfo", TreeUtils.toTree(menuList, 0L));

        return map;
    }


    @Override
    public List<SysMenu> byUserNameQueryMenu(String userName) {
        return null;
//        return sysMenuMapper.byUserNameQueryMenu(userName);
    }


}
